import './my.html';
import { Message } from '../../components/message/message.js';

Template.App_my.onCreated(function(){
  let self = this;
  console.log(FlowRouter.getParam('username'));
  self.user = new ReactiveVar();

  self.loadready = new ReactiveVar(false);


  self.loadready.set(FlowRouter.subsReady("userpage"));
  self.autorun(function(){
    if (self.loadready) {
      let user  = Meteor.users.findOne({username: FlowRouter.getParam("username")});
      console.log(user);
      self.user.set(user);
    }
    if (self.user.get()) {


      if (self.user.get().fansCount == undefined) {
        console.log('开始处理');
      }
    }

  });

});


Template.App_my.onRendered(function(){
  let self = this;
  $('.menu .item').tab();
});

Template.App_my.helpers({

  moment(date){
    return moment(date, "YYYYMMDD").fromNow();
  },
  username(){
    return FlowRouter.getParam('username');
  },
  nickname(){
    return '花名未设置';
  },
  isEditable(){
    if (Meteor.user().username == FlowRouter.getParam('username')) {
      return true;
    }
    return false;
  },

});

Template.App_my.events({
	'click .link_logout'(){
		event.preventDefault();
    event.stopPropagation();
		Meteor.logout(function(){
      Message.sendSuccess("您已安全退出～");
      FlowRouter.go('/');
    });

	}
});
